package com.example.wc.logindemo.blogdb;

import android.database.Cursor;
import android.database.CursorWrapper;

import com.example.wc.logindemo.Blog;
import com.example.wc.logindemo.blogdb.BlogDbSchema.BlogTable;

import java.util.Date;

/**
 * Created by hui on 2017/3/8.
 */

public class BlogCursorWrapper extends CursorWrapper {
    /**
     * Creates a cursor wrapper.
     *
     * @param cursor The underlying cursor to wrap.
     */
    public BlogCursorWrapper(Cursor cursor) {
        super(cursor);
    }

    public Blog getBlog(){
        String id = getString(getColumnIndex(BlogTable.Cols.ID));
        String name = getString(getColumnIndex(BlogTable.Cols.NAME));
        String content = getString(getColumnIndex(BlogTable.Cols.CONTENT));
        long date = getLong(getColumnIndex(BlogTable.Cols.DATE));

        Blog blog = new Blog(id);
        blog.setName(name);
        blog.setDate(new Date(date));
        blog.setContent(content);

        return blog;
    }

    public String getId(){
        String id = getString(getColumnIndex(BlogTable.Cols.ID));
        return id;
    }
}
